package com.sanyang.pda.presenter;

import com.sanyang.pda.bean.RandomSamplingBean;
import com.sanyang.pda.contract.ReplaceListContract;
import com.sanyang.pda.net.NetUtils;
import com.wangshen.base.net.bean.BaseRowsAppEntity;
import com.wangshen.base.ui.mvp.base.refresh.BaseRecyclerRefreshPresenter;
import com.wangshen.base.ui.mvp.base.refresh.RequestCallback;

import java.util.List;

import io.reactivex.functions.Consumer;

public class RepalceListPresenter extends BaseRecyclerRefreshPresenter<ReplaceListContract.View, RandomSamplingBean> implements  ReplaceListContract.Presnter{
    @Override
    public void samplingResultList(RequestCallback<RandomSamplingBean> callback) {
        NetUtils.geApi().samplingList(getCurrentPage(),10)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseRowsAppEntity<List<RandomSamplingBean>>>() {
                    @Override
                    public void accept(BaseRowsAppEntity<List<RandomSamplingBean>> listBaseRowsAppEntity) throws Exception {
                        callback.onSuccess(listBaseRowsAppEntity.getRows());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void onRefresh(RequestCallback<RandomSamplingBean> callback) {
        samplingResultList(callback);
    }

    @Override
    public void onLoadMore(RequestCallback<RandomSamplingBean> callback) {
        samplingResultList(callback);
    }
}
